/*
   Author: mahaiyuan
   Date: 2021/9/5 10:16 下午
   Description:
*/
package zlog

import (
	"go.uber.org/zap"
)

func getSugaredLogger() *zap.SugaredLogger {
	if SugaredLogger == nil {
		mlock.Lock()
		SugaredLogger = newLogger().Sugar()
		mlock.Unlock()
	}
	return SugaredLogger
}

// Debug uses fmt.Sprint to construct and log a message.
func Debug(args ...interface{}) {
	getSugaredLogger().Debug(args)
}
// Debugf uses fmt.Sprintf to log a templated message.
func Debugf(template string, args ...interface{}) {
	getSugaredLogger().Debugf(template, args)
}
// Debugw logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
//
// When debug-level logging is disabled, this is much faster than
//  s.With(keysAndValues).Debug(msg)
func Debugw(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().Debugw(msg, keysAndValues)
}

// Info uses fmt.Sprint to construct and log a message.
func Info(args ...interface{}) {
	getSugaredLogger().Info(args)
}
// Infof uses fmt.Sprintf to log a templated message.
func Infof(template string, args ...interface{}) {
	getSugaredLogger().Infof(template, args)
}
// Infow logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func Infow(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().Infow(msg, keysAndValues)
}

// Warn uses fmt.Sprint to construct and log a message.
func Warn(args ...interface{}) {
	getSugaredLogger().Warn(args)
}
// Warnf uses fmt.Sprintf to log a templated message.
func Warnf(template string, args ...interface{}) {
	getSugaredLogger().Warnf(template, args)
}
// Warnw logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func Warnw(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().Warnw(msg, keysAndValues)
}

// Error uses fmt.Sprint to construct and log a message.
func Error(args ...interface{}) {
	getSugaredLogger().Error(args)
}
// Errorf uses fmt.Sprintf to log a templated message.
func Errorf(template string, args ...interface{}) {
	getSugaredLogger().Errorf(template, args)
}
// Errorw logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func Errorw(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().Errorw(msg, keysAndValues)
}

// DPanic uses fmt.Sprint to construct and log a message. In development, the
// logger then panics. (See DPanicLevel for details.)
func DPanic(args ...interface{}) {
	getSugaredLogger().DPanic(args)
}
// DPanicf uses fmt.Sprintf to log a templated message. In development, the
// logger then panics. (See DPanicLevel for details.)
func DPanicf(template string, args ...interface{}) {
	getSugaredLogger().DPanicf(template, args)
}
// DPanicw logs a message with some additional context. In development, the
// logger then panics. (See DPanicLevel for details.) The variadic key-value
// pairs are treated as they are in With.
func DPanicw(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().DPanicw(msg, keysAndValues)
}

// Panic uses fmt.Sprint to construct and log a message, then panics.
func Panic(args ...interface{}) {
	getSugaredLogger().Panic(args)
}
// Panicf uses fmt.Sprintf to log a templated message, then panics.
func Panicf(template string, args ...interface{}) {
	getSugaredLogger().Panicf(template, args)
}
// Panicw logs a message with some additional context, then panics. The
// variadic key-value pairs are treated as they are in With.
func Panicw(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().Panicw(msg, keysAndValues)
}

// Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
func Fatal(args ...interface{}) {
	getSugaredLogger().Fatal(args)
}
// Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func Fatalf(template string, args ...interface{}) {
	getSugaredLogger().Fatalf(template, args)
}
// Fatalw logs a message with some additional context, then calls os.Exit. The
// variadic key-value pairs are treated as they are in With.
func Fatalw(msg string, keysAndValues ...interface{}) {
	getSugaredLogger().Fatalw(msg, keysAndValues)
}
